import axios from './axios'
import qs from 'qs'



export function getDepartmentList() {
    return axios.get('/sys/dept/dept_tree.do').then(res=>{
        return Promise.resolve(res.data)
    },err=>{
        return Promise.reject(err)
    })
}
//增加部门 seq =》展示顺序
export function addDepartment({ name,parentId,seq,remark }) {
    return axios.post('/sys/dept/add_dept.do',qs.stringify({name,parentId,seq,remark})).then(res=>{
        return Promise.resolve(res.data)
    },err=>{
        return Promise.reject(err)
    })
}
//修改部门
export function modDepartment({ id,name,parentId,seq,remark }) {
    return axios.post('/sys/dept/update_dept.do',qs.stringify({id,name,parentId,seq,remark})).then(res=>{
        return Promise.resolve(res.data)
    },err=>{
        return Promise.reject(err)
    })
}
// delete department
export  function deleteDepartment(id) {
    return axios.post('/sys/dept/delete_dept.do',qs.stringify({id})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}



export function getUserList(deptId) {
    return axios.post('/sys/user/user_list.do',qs.stringify({deptId})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function addUser({loginName,username,telephone,deptId,status,remark}) {
    return axios.post("/sys/user/add_user.do",qs.stringify({loginName,username,telephone,deptId,status,remark})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}

export function modUser({ id,loginName,username,telephone,deptId,status,remark}) {
    return axios.post('/sys/user/update_user.do',
        qs.stringify({ id,loginName,username,telephone,deptId,status,remark })).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function deleteUser(id) {
    return axios.post('/sys/user/delete_user.do',qs.stringify({id})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}



export function getRoleList() {
    return axios.get('/sys/role/role_list.do').then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function addRole({name,type,status,remark}) {
    return axios.post('/sys/role/save_role.do',qs.stringify({name,type,status,remark})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function modRole({id,name,type,status,remark}) {
    return axios.post('/sys/role/update_role.do',qs.stringify({id,name,type,status,remark})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
//角色权限树
export function getRoleTree(roleId){
    return axios.post('/sys/role/role_tree.do',qs.stringify({roleId,userId:1})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function getRoleUser(roleId) {
    return axios.post('/sys/role/users.do',qs.stringify({roleId})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function changeAcls({roleId,aclIds}) {
    return axios.post('/sys/role/change_acls.do',qs.stringify({roleId,aclIds})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}
export function changeUsers({roleId,userIds}) {
    return axios.post('/sys/role/change_users.do',qs.stringify({roleId,userIds})).then(res=>Promise.resolve(res.data),err=>Promise.reject(err))
}


//moduel
export function getModuleTree() {
    return axios.post('/sys/aclModule/acl_module_tree.do').then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}

export function addModuleTree({name,parentId,seq,status,remarks}) {
    return axios.post('/sys/aclModule/save_acl_module.do',qs.stringify({name,parentId,seq,status,remarks})).then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}

export function modModuleTree({id,name,parentId,seq,status,remarks}) {
    return axios.post('/sys/aclModule/update_acl_module.do',qs.stringify({id,name,parentId,seq,status,remarks})).then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}

export function deleteModuleTree(aclModuleId) {
    return axios.post('/sys/aclModule/delete_acl_module.do',qs.stringify({aclModuleId})).then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}

//acl point
export function getAclList(aclModuleId,pageSize=50) {
    return axios.post('/sys/acl/acl_list.do',qs.stringify({aclModuleId,pageSize})).then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}
export function addAcl({aclModuleId,url,type,seq,status,remark,name}) {
    return axios.post('/sys/acl/save_acl.do',qs.stringify({aclModuleId,url,type,seq,status,remark,name})).then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}
export function modAcl({id,aclModuleId,url,type,seq,status,remark,name}) {
    return axios.post('/sys/acl/update_acl.do',qs.stringify({id,aclModuleId,url,type,seq,status,remark,name})).then(res=>Promise.resolve(res.data),err=>Promise.resolve(err))
}